﻿Public Class DinnerRepository
    Private db As New NerdDinnerDataContext

    Public Function FindAllDinners() As IQueryable(Of Dinner)
        Return db.Dinners
    End Function

    Public Function FindUpcomingDinners() As IQueryable(Of Dinner)
        Return From d In db.Dinners
               Where d.EventDate > Now
               Order By d.EventDate
               Select d
    End Function

    Public Function GetDinner(ByVal id As Integer) As Dinner
        Return db.Dinners.SingleOrDefault(Function(d) d.DinnerID = id)
    End Function

    Public Sub Add(ByVal d As Dinner)
        db.Dinners.InsertOnSubmit(d)
    End Sub

    Public Sub Delete(ByVal d As Dinner)
        db.RSVPs.DeleteAllOnSubmit(d.RSVPs)
        db.Dinners.DeleteOnSubmit(d)
    End Sub

    Public Sub Save()
        db.SubmitChanges()
    End Sub
End Class
